# Maintainer: Alexey Pavlov <alexpux@gmail.com>

_realname=lua

pkgname="${MINGW_PACKAGE_PREFIX}-${_realname}"
pkgver=5.2.3
pkgrel=2
pkgdesc="A powerful light-weight programming language designed for extending applications. (mingw-w64)" 
arch=('any')
url="http://www.lua.org/" 
license=('MIT')
makedepends=("${MINGW_PACKAGE_PREFIX}-gcc")
options=('staticlibs' 'strip' 'emptydirs')
source=($url/ftp/lua-$pkgver.tar.gz
    'lua.pc')
md5sums=('dc7f94ec6ff15c985d2d6ad0f1b35654'
         'e7ba6c2b695b0b84a5ea0cbff5fc9067')

build() {
  cp ${srcdir}/lua.pc ${srcdir}/${_realname}-${pkgver}/
  cd ${srcdir}/${_realname}-${pkgver}
  sed -e "s|%VER%|${pkgver%.*}|g;s|%REL%|$pkgver|g" \
    -e "s|/usr|${MINGW_PREFIX}|g" \
    -i lua.pc

  make -j1 \
    AR="ar rcu" \
    RANLIB="ranlib" \
    STRIP="strip" \
    CC="${MINGW_CHOST}-gcc" \
    INSTALL_TOP="${pkgdir}${MINGW_PREFIX}" \
    INSTALL_MAN="${pkgdir}${MINGW_PREFIX}"/share/man/man1 \
    TO_BIN="lua.exe luac.exe lua52.dll" \
    mingw install
  make clean
}

package() {
  cd ${srcdir}/${_realname}-${pkgver}
  install -Dm644 lua.pc "${pkgdir}${MINGW_PREFIX}"/lib/pkgconfig/lua.pc

  # Install the documentation
  install -d "${pkgdir}${MINGW_PREFIX}"/share/doc/lua
  install -m644 doc/*.{gif,png,css,html} "${pkgdir}${MINGW_PREFIX}"/share/doc/lua
}
